package com.bohua.intermediary.service.impl;

import com.bohua.intermediary.common.Lay;
import com.bohua.intermediary.common.Msg;
import com.bohua.intermediary.dao.SysAchievementMapper;
import com.bohua.intermediary.entity.SysAchievement;
import com.bohua.intermediary.service.SysAchievementService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 服务实现
 * @author qian
 * @email 1415261159@qq.com
 * @date 2019/01/19
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysAchievementServiceImpl implements SysAchievementService {
    @Resource
    private SysAchievementMapper sysAchievementMapper;

    @Override
    public Msg addSysAchievement(SysAchievement sysAchievement) {
        int i=  sysAchievementMapper.insert(sysAchievement);
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("添加成功");
        }else{
            msg.setCode(-1);
            msg.setMsg("添加失败");
        }
        return msg;
    }

    @Override
    public Msg updateSysAchievement(SysAchievement sysAchievement) {
        int i= sysAchievementMapper.updateByParam(sysAchievement);
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("修改成功");
        }else{
            msg.setCode(-1);
            msg.setMsg("修改失败");
        }
        return msg;
    }

    @Override
    public Msg delSysAchievement(SysAchievement sysAchievement) {
        int i=sysAchievementMapper.del(sysAchievement.getId());
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("删除成功");
        }else{
            msg.setCode(-1);
            msg.setMsg("删除失败");
        }
        return msg;
    }

    @Override
    public Lay getSysAchievements(SysAchievement sysAchievement, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<SysAchievement> sysAchievements=sysAchievementMapper.list(sysAchievement);
        PageInfo info=new PageInfo(sysAchievements);
        Lay lay=new Lay();
        lay.setPage(page);
        lay.setCount(info.getTotal());
        lay.setData(info.getList());
        return lay;
    }
}
